#pragma once
#include "types.h"
#include "rng.h"

const uint32_t ChunkSize = 1024; //allocates chunks of 1k bools at time

class CMessage
{

public:
    CMessage(double sigma){
        mSigma = sigma;
        mBoolMessage = new bool[ChunkSize];
        if(mBoolMessage!=NULL){
            mMaxMessageSize = ChunkSize;
        }
        mDoubleMessage = NULL;
		mDoubleNoisyMessage = NULL;
        mMessageSize = 0;        
    };

    ~CMessage(void){
        if(mBoolMessage!=NULL){
            delete mBoolMessage;
        }

        if(mDoubleMessage!=NULL){
            delete mDoubleMessage;
        }

		if(mDoubleNoisyMessage!=NULL){
            delete mDoubleNoisyMessage;
        }
    };
    
    void            CreateRandom(uint32_t size);
    
    void            Append(bool* message, uint32_t size);
    void            Replace(bool* message, uint32_t size);
	void            Replace(double* message, uint32_t size);

    bool*           GetBoolMessage() {return mBoolMessage;};
    double*         GetDoubleMessage() {return mDoubleMessage;};
	double*         GetDoubleNoisyMessage() {return mDoubleNoisyMessage;};
	double			GetSigma() {return mSigma;};

    uint32_t        GetSize() {return mMessageSize;};

    void            Puncture(uint32_t start, uint32_t rate);
	
	void			Copy(CMessage* source);
	void			ComposeFromDump(char* arq);
	
	uint32_t		Compare(CMessage* msg);
	uint32_t		Compare(CMessage* msg, bool debug);
	void			UpdateDoubleMessage();   


private:

    
    double  Gaussian();
    void ResizeMessage(uint32_t size);

//private:
public: //for debugging only

    bool*       mBoolMessage;
    double*     mDoubleMessage;
	double*     mDoubleNoisyMessage;
    uint32_t    mMessageSize;
    uint32_t    mMaxMessageSize;
    double      mSigma;

};
